package com.zzh.tools.utils;


import com.zzh.tools.system.ToolThrow;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangzhihao
 * @email zhangzhihao@gongjiangren.net
 * @date 2020-07-15
 * @desc map生成器
 */
public class ToolMap {

    public static Map<String, Object> createMap(Object... objects) {
        ToolThrow.isLengthEvenNumberThrow(objects);
        Map<String, Object> map = new HashMap<>(objects.length);
        for (int i = 0; i < objects.length; i += 2) {
            map.put((String) objects[i], objects[i + 1]);
        }
        return map;
    }

    public static Map<Integer, Object> createIntMap(Object... objects) {
        ToolThrow.isLengthEvenNumberThrow(objects);
        Map<Integer, Object> map = new HashMap<>(objects.length);
        for (int i = 0; i < objects.length; i += 2) {
            map.put((int) objects[i], objects[i + 1]);
        }
        return map;
    }

    public static Map<String, String> createStrStrMap(String... str) {
        ToolThrow.isLenghtEvenNumberThrow(str);
        Map<String, String> map = new HashMap<>(str.length);
        for (int i = 0; i < str.length; i += 2) {
            map.put(str[i], str[i + 1]);
        }
        return map;
    }

    public static Map<String, Boolean> createStrBoolMap(Object... objects) {
        ToolThrow.isLengthEvenNumberThrow(objects);
        Map<String, Boolean> map = new HashMap<>(objects.length);
        for (int i = 0; i < objects.length; i += 2) {
            map.put((String) objects[i], (Boolean) objects[i + 1]);
        }
        return map;
    }

}
